﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ParserCore;

namespace TestParser
{
    [TestClass]
    public partial class ExpressionEquality
    {
        [TestMethod]
        public void ConstantEqualityTest()
        {
            var cs1 = new Constant("2", Constant.CType.String);
            var cs2 = new Constant("2", Constant.CType.String);
            Assert.AreEqual(cs1, cs2);
        }

        [TestMethod]
        public void ConstantInequalityTest()
        {
            var cs1 = new Constant("2", Constant.CType.String);
            var cs2 = new Constant("23", Constant.CType.String);
			var cs3 = new Constant("2", Constant.CType.RealNumber);
			var cs4 = new Constant("23", Constant.CType.RealNumber);
            Assert.AreNotEqual(cs1, cs2);
			Assert.AreNotEqual(cs1, cs3);
			Assert.AreNotEqual(cs1, cs4);
        }
        [TestMethod]
        public void CallEqualityTest()
        {

            var exp1 = new Call(
                new Identifier("+"),
                new Constant("2"),
                new Call(
                    new Identifier("*"),
                    new Constant("3"),
                    new Constant("5")
                )
            );
            var exp2 = new Call(
                new Identifier("+"),
                new Constant("2"),
                new Call(
                    new Identifier("*"),
                    new Constant("3"),
                    new Constant("5")
                )
            );
            Assert.AreEqual(exp1, exp2);
        }

        [TestMethod]
        public void CallInequalityTest()
        {

            var exp1 = new Call(
                    new Identifier("+"),
                        new Constant("5"),
                        new Constant("5")
                    );
            var exp2 = new Call(
                    new Identifier("+"),
                        new Constant("5")
                    );
            var exp3 = new Call(
                    new Identifier("+"),
                        new Constant("5"),
                        new Constant("5"),
                        new Constant("5")
                    );
            var exp4 = new Call(
                    new Identifier("+"),
                        new Constant("5"),
                        new Constant("0")
                    );

            Assert.AreNotEqual(exp1, exp2);
            Assert.AreNotEqual(exp1, exp3);
            Assert.AreNotEqual(exp1, exp4);
        }
        [TestMethod]
        public void NDimArrayBuilderEqualityTest()
        {
            var exp1 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("3"),
                    new Identifier("a")
                }, new Expression[] {
                    new Call (
                        new Identifier("+"),
                        new Constant("5"),
                        new Identifier("a")
                    ),
                    new Identifier("b")
                }
            });
            var exp2 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("3"),
                    new Identifier("a")
                }, new Expression[] {
                    new Call (
                        new Identifier("+"),
                        new Constant("5"),
                        new Identifier("a")
                    ),
                    new Identifier("b")
                }
            });
            Assert.AreEqual(exp1, exp2);
        }
        [TestMethod]
        public void NDimArrayBuilderInqualityTest()
        {
            var exp1 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }
            });
            var exp2 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("0")
                }
            });
            var exp3 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5")
                }
            });
            var exp4 = new NDimArrayBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }
            });
            Assert.AreNotEqual(exp1, exp2);
            Assert.AreNotEqual(exp1, exp3);
            Assert.AreNotEqual(exp1, exp4);
        }
        [TestMethod]
        public void CellBuilderEqualityTest()
        {
            var exp1 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("3"),
                    new Identifier("a")
                }, new Expression[] {
                    new Call (
                        new Identifier("+"),
                        new Constant("5"),
                        new Identifier("a")
                    ),
                    new Identifier("b")
                }
            });
            var exp2 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("3"),
                    new Identifier("a")
                }, new Expression[] {
                    new Call (
                        new Identifier("+"),
                        new Constant("5"),
                        new Identifier("a")
                    ),
                    new Identifier("b")
                }
            });
            Assert.AreEqual(exp1, exp2);
        }
        [TestMethod]
        public void CellBuilderInqualityTest()
        {
            var exp1 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }
            });
            var exp2 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("0")
                }
            });
            var exp3 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5")
                }
            });
            var exp4 = new CellBuilder(new Expression[][] {
                new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                }, new Expression[] {
                    new Constant("5"),
                    new Constant("5"),
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }, new Expression[] {
                    new Constant("5")
                }
            });
            Assert.AreNotEqual(exp1, exp2);
            Assert.AreNotEqual(exp1, exp3);
            Assert.AreNotEqual(exp1, exp4);
        }
        [TestMethod]
        public void AnonymousFunctionBuilderEqualityTest()
        {
            var exp1 = new AnonymousFunctionBuilder(
                new Identifier[]{
                    new Identifier("a1"),
                    new Identifier("a2"),
                    new Identifier("a3")},
                new Constant("5"));
            var exp2 = new AnonymousFunctionBuilder(
                    new Identifier[]{
                        new Identifier("a1"),
                        new Identifier("a2"),
                        new Identifier("a3")},
                    new Constant("5"));
            Assert.AreEqual(exp1, exp2);
        }

        [TestMethod]
        public void AnonymousFunctionBuilderInequalityTest()
        {
            var exp = new AnonymousFunctionBuilder(
                new Identifier[]{
                    new Identifier("a1"),
                    new Identifier("a2"),
                    new Identifier("a3")},
                new Constant("5"));
            var exp1 = new AnonymousFunctionBuilder(
                    new Identifier[]{
                        new Identifier("b1"),
                        new Identifier("a2"),
                        new Identifier("a3")},
                    new Constant("5"));
            var exp2 = new AnonymousFunctionBuilder(
                    new Identifier[]{
                        new Identifier("a1"),
                        new Identifier("a2"),
                        new Identifier("a3"),
                        new Identifier("a4")},
                    new Constant("5"));
            var exp3 = new AnonymousFunctionBuilder(
                    new Identifier[]{
                        new Identifier("a1"),
                        new Identifier("a2"),
                        new Identifier("a3")},
                    new Constant("0"));
            Assert.AreNotEqual(exp, exp1);
            Assert.AreNotEqual(exp, exp2);
            Assert.AreNotEqual(exp, exp3);
        }

    }
}
